home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / WWW / http / www.amitrix.com / AWebFTP.lha / AWebftp.awebrx next >
Text File  |  1996-11-02  |  17KB  |  434 lines

  1. /* AwebFTP - FTP plug-in for Aweb
  2.  
  3. */ vers="Version 1.3a (AmiTrix 2.1)"
  4. /*
  5.     By Josef Faulkner (panther@gate.net) IRC: Josef
  6.         Modified by AmiTrix Development for inclusion with AWeb-II
  7.           Added config program and file
  8.           Fixed a couple bugs 
  9.  
  10.     Description:
  11.     ¯¯¯¯¯¯¯¯¯¯¯¯
  12.     This plugin will allow you to do inline FTPing of files on the net,
  13.     without the need to call an external FTP program (except FTPMount, which
  14.     is transparent).  It will distinguish between a directory and a file, and
  15.     act accordingly.
  16.  
  17.     Features:
  18.     ¯¯¯¯¯¯¯¯¯
  19.         o Fast reaction, since FTPMount does a lot of cacheing of dirs
  20.         o Asyncronous download (thanks to Aweb), you can continue browsing
  21.           while it downloads, and Aweb will inform you when the transfer
  22.           has completed!
  23.         o Brings up a requestor to ask what you want to save as
  24.     New for 1.1:
  25.         o You can now upload to the directory if you type the name of a file
  26.           in a form at the bottom of the list (or leave blank, and it will
  27.           give you a requester asking for a file)
  28.         o Make directories
  29.         o Delete a file (only one at a time, currently)
  30.     New for 1.2:
  31.         o WBCopy command used to copy files w/ progress meter
  32.           Thanks to Bastian H. Frank for developing this handy program!
  33.     New for 1.3:
  34.         o Much faster:
  35.             o No longer parses list output, uses lformat to create listing
  36.         o AmiFTP is now loadable from the inside!
  37.             o Will detect if amiftp is already loaded, and go to the directory
  38.             o Doesn't disconnect and reconnect if amiftp already has the host open
  39.     New for 1.3a:
  40.         o Plaincopy used by default for Aweb II Distribution.
  41.         o Fixed some minor bugs
  42.  
  43.     Requirements:
  44.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  45.     FTPMount version 8 (or newer) must be installed and running
  46.         available on Aminet:
  47.         FTPMount-1.0.lha  comm/tcp   109K Mounts FTP sites
  48.     Copy command, choose one (set below, must be in your path):
  49.         plaincopy (included in this archive)
  50.         WBCopy (aminet/util/cli/WBCopy.lha) - Does progress meters
  51.         copy (comes with workbench) - has problems with softlinked files
  52.     AmiFTP (from http://www.lysator.liu.se/~lilja/AmiFTP.html)
  53.         To be launched by a button if a separate GUI is preferred!
  54.         (optional)
  55.  
  56.     Installation:
  57.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  58.     1) Put this script in the same directory that the Aweb executable is in.
  59.     2) Set Aweb to the following settings:
  60.       ----------------------------------------------
  61.         Network 3: External Programs
  62.                    ftp:
  63.           Command:  sys:rexxc/rx
  64.         Arguments:  awebftp.rexx %s %s %s  <--- *** NOTE *THREE* %s's ***
  65.       ----------------------------------------------
  66.     3) Put plainCopy in your path (ie C:)
  67.     4) Set your preferences for this script below:
  68.  
  69.     Known Bugs:
  70.     ¯¯¯¯¯¯¯¯¯¯¯
  71.     Linked files are sometimes thought to be directories in AmigaDOS, and
  72.     may wind up returning an empty directory listing instead of the actual
  73.     file.
  74.     I've attempted to correct this by checking if the link clicked on has a
  75.     period in the name, if so, it assumes it's a file instead.
  76.     Hopefully this bug is obsolete with the new copy program.  Let me know if
  77.     you find any URL's that this still happens on.
  78.  
  79.     Many people are getting "out of memory" errors.  This should only be
  80.     occuring on old versions of AwebFTP, and usually only when they forget
  81.     to pass all three %s arguments in aweb's preferences.
  82. */
  83.  
  84. /****AwebFTP Preferences***********************************************/
  85.  
  86. savedir='RAM:'                /* Default directory to download to */
  87. copycommand='AWeb-II:plugins/AwebFTP/plaincopy'       /* Set to program used to copy (use plaincopy for best compatibility) */
  88. amiftpexe=''                  /* Path and name of your amiftp executable */
  89.  
  90. /* Change by Amitrix to get configuration from file and find the current    */
  91. /* AWeb Window   */
  92.  
  93. options results
  94.  
  95. ports = show('P')
  96. parse var ports dummy 'AWEB.' portnr .
  97. address value 'AWEB.' || portnr
  98.  
  99. 'GET ACTIVEPORT'
  100.  
  101. awebhost = result
  102.  
  103. if Open(config_fp,"AWebFtp.config",r) then
  104.   do
  105.     savedir = readln(config_fp)
  106.     amiftpexe = readln(config_fp)
  107.     call close(config_fp)
  108.    end
  109.  
  110. parse source prog_type result_flag called resolved ext host .
  111.  
  112. last_slash = lastpos('/',called)
  113. last_colon = lastpos(':',called)
  114.  
  115. dir_pos = max(last_slash,last_colon)
  116. if dir_pos > 0 then
  117.   current_dir = left(called,dir_pos)
  118.  else
  119.    current_dir = '' 
  120.  
  121. Address value awebhost
  122.  
  123.  
  124. if Open(config_fp,current_dir||"AWebFTP.config",r) then
  125.   do
  126.     save_dir = readln(config_fp)
  127.     AmiFTPexe = readln(config_fp)
  128.     call close(config_fp)
  129.    end
  130. /* End AmiTrix Changes */
  131.  
  132. /**********************************************************************/
  133.  
  134. if ~show('L','rexxsupport.library') then
  135.   if ~addlib('rexxsupport.library',0,-30,0) then 
  136.     exit 20
  137.  
  138. tmpfile='t:awebftp'time(S)'.html'
  139. address command 'delete t:awebftp#? >NIL:'
  140. parse arg cmds
  141.  
  142. /* Added by AmiTrix to Check for screen not being passed and FTP: not */
  143. /* being mounted                                                      */
  144.  
  145. parse var cmds '"'server'"' '"'file'"' screen
  146. if screen = '' then
  147.   do
  148.     'GET SCREEN'
  149.     screen = result
  150.    end
  151.  
  152. address command 'assign FTP: >NIL: exists'
  153.  
  154. if rc > 0 then
  155.   if exists('sys:storage/dosdrivers/ftp') then
  156.     address command 'mount ftp:'
  157.  
  158. /* End AmiTrix changes */
  159.      
  160. if left(upper(cmds),3)='URL' then do
  161.     do until cmds=''
  162.         parse var cmds name'="'value'"'cmds
  163.         if left(cmds,1)='&' then cmds=right(cmds,length(cmds)-1)
  164.         interpret name'=value'
  165.     end
  166.     select
  167.         when function='upload' then do
  168.             call open(1,tmpfile,w)
  169.             call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  170.             if (exists(file))&(file~='FILE') then do
  171.                 address command 'copy 'text' 'url        
  172.                 if rc<20 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2>')
  173.                 else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  174.             end
  175.             else do
  176.                 address command 'requestfile RAM: >t:awebftp.tmp'
  177.                 call open(2,'t:awebftp.tmp',r)
  178.                 text=readln(2)
  179.                 call close(2)
  180.                 if word(text,1)~='no' then do
  181.                     parse var text .'"'text'"'.
  182.                     if exists(text) then do
  183.                         call putawebmsg('<h3>Now uploading 'text' to 'url'.</h3>You may continue using Aweb asyncronously (especially if file is long).')
  184.                         address command 'copy 'text' 'url
  185.                         if rc<10 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2><a href="'url'">Go Back</a>')
  186.                         else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  187.                     end
  188.                     else call writeln(1,'<h1>Error</h1><h3>Could not open <b>'text'</b> to send</h3>')
  189.                 end
  190.                 else call writeln(1,'<h1>Transfer Cancelled</h1>')
  191.             end
  192.             call writeln(1,'</body></html>')    
  193.             call close(1)
  194.             'OPEN file://localhost/'tmpfile
  195.             exit
  196.         end
  197.         when function='makedir' then do
  198.             if file~='FILE' then do
  199.                 if exists(url||file) then call putawebmsg("Directory already exists!")
  200.                 else do
  201.                     call putawebmsg("Making directory.  Please wait.<h5>(Ignore this if [Back]ing up)</h5>")
  202.                     address command 'makedir 'url||file
  203.                     if rc<10 then call putawebmsg('Directory 'file' created successfully. <br><a href="'url'">Go Back</a>')
  204.                     else call putawebmsg("<h1>Error</h1>Directory was NOT created.")
  205.                 end
  206.             end
  207.             else call putawebmsg("No directory specified.")
  208.             exit
  209.         end
  210.         when function='delete' then do
  211.             if file~='FILE' then do
  212.                 if exists(url||file) then do
  213.                     address command 'requestchoice "Delete File" "Delete 'file' ?" "Delete|Cancel" >t:awebftpchoice.tmp'
  214.                     if open(1,'t:awebftpchoice.tmp',r) then do
  215.                         text=readln(1)
  216.                         if strip(text)='1' then do
  217.                             address command 'delete 'url||file' >t:awebftp.tmp'
  218.                             if rc<10 then call putawebmsg('File <b>'file'</b> deleted. <br><a href="'url'">Go Back</a>')
  219.                             else call putawebmsg("<h1>Error</h1>Error with deletion")                
  220.                         end
  221.                         else call putawebmsg("Delete Cancelled.")
  222.                     end
  223.                 end
  224.                 else call putawebmsg('<h1>Error</h1><b>'file'</b> does not exist!')
  225.             end
  226.             else call putawebmsg("No directory specified.")
  227.             exit
  228.         end
  229.         when function='amiftp' then do
  230.             parse var url 'ftp://'hostname'/'dirs
  231.             dirs='/'dirs
  232.             if showlist(P,'AMIFTP') then do
  233.                 address 'AMIFTP' 'GETATTR STEM ainfo'
  234.                 if (ainfo.HOST ~= hostname) then do
  235.                     address 'AMIFTP' 'DISCONNECT'
  236.                     address 'AMIFTP' 'SETATTR HOST' hostname
  237.                     address 'AMIFTP' 'CONNECT NOSCAN'
  238.                 end
  239.                 address 'AMIFTP' 'CD' dirs
  240.             end
  241.             else do
  242.                 address command amiftpexe
  243.                 timeout=0
  244.                 address command 'waitforport AMIFTP'
  245.                 if (showlist(P,'AMIFTP')) then do
  246.                     address 'AMIFTP' 'GETATTR STEM ainfo'
  247.                     if (ainfo.HOST ~= hostname) then do
  248.                         address 'AMIFTP' 'DISCONNECT'
  249.                         address 'AMIFTP' 'SETATTR HOST' hostname
  250.                         address 'AMIFTP' 'CONNECT NOSCAN'
  251.                     end
  252.                     address 'AMIFTP' 'CD' dirs
  253.                 end
  254.                 else do
  255.                     putawebmsg('Error: Couldn''t run AmiFTP')
  256.                     exit
  257.                 end
  258.             end
  259.         end    
  260.         otherwise do
  261.             call putawebmsg('Program Error: please <a href="mailto:panther@gate.net">mail</a> author w/ errorcode: F-'function' and conditions under which it failed.')
  262.         end
  263.     end
  264.     exit
  265. end
  266.  
  267. if server='about' then do
  268.     call open(1,tmpfile,w)
  269.     call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  270.     call writeln(1,'<h1>About AwebFTP 'word(vers,2)'</h1>')
  271.     call writeln(1,'AwebFTP is an FTP plug-in arexx script for Aweb, which does FTP inside Aweb''s GUI, provided you have FTPMount installed')
  272.     call writeln(1,'<p><h2>Features of AwebFTP</h2><ul>')
  273.     call writeln(1,'<li>Fast reaction, since FTPMount does caches dirs.')
  274.     call writeln(1,'<li>Inline - Stays within the Aweb GUI.')
  275.     call writeln(1,'<li>Asyncronous download (thanks to Aweb), you can continue browsing while it downloads, and Aweb will inform you when the transfer has completed!')
  276.     call writeln(1,'<li>Brings up a requestor to ask what you want to save as.')
  277.     call writeln(1,'</ul>New for 1.1:<ul>')
  278.     call writeln(1,'<li>You can now upload to the directory if you type the name of a file in a form at the bottom of the list (or leave blank, and it will give you a requester asking for a file)')
  279.     call writeln(1,'<li>Make directories')
  280.     call writeln(1,'<li>Delete a file (currently only one file at a time)')
  281.     call writeln(1,'<li>Title is now a link: click to refresh the list after send/makedir/delete, etc')
  282.     call writeln(1,'</ul>New for 1.2:<ul>')
  283.     call writeln(1,'<li>WBCopy command used to copy files with progress meter')
  284.     call writeln(1,'<br>Thanks to Bastian H. Frank for developing this handy program!')
  285.     call writeln(1,'</ul>New for 1.3:<ul>')
  286.     call writeln(1,'<li>Much faster:<ul>')
  287.     call writeln(1,'<li>No longer parses list output, uses lformat to create listing')
  288.     call writeln(1,'</ul><li>AmiFTP can now be automatically loaded and set to the current dir!<ul>');
  289.     call writeln(1,'<li>Will detect if amiftp is already loaded, and go to the directory');
  290.     call writeln(1,'<li>Doesn''t disconnect and reconnect if amiftp already has the host open');
  291.     call writeln(1,'</ul></ul>')
  292.     call writeln(1,'</ul><p><h2>Known Bugs</h2><ul>')
  293.     call writeln(1,'<li>Linked files are sometimes thought to be directories in AmigaDOS, and may wind up returning an empty directory listing instead of the actual file.')
  294.     call writeln(1,'<p>I''ve attempted to correct this by checking if the link clicked on has a period in the name, if so, it assumes it''s a file instead.  Hopefully this bug is obsolete with the new copy program.  Let me know if you find any URL''s that this still happens on.<p>')
  295.     call writeln(1,'<li>Many people are getting "out of memory" errors.  This should only be    occuring on old versions of AwebFTP, and usually only when they forget    to pass all three %s arguments in aweb''s preferences.  If this is still occuring in this version for you, PLEASE let me know the URL.')
  296.     call writeln(1,'</ul><p><h2>AwebFTP Author</h2>')
  297.     call writeln(1,'<p>AwebFTP is written by <a href="http://www.versanet.com/~josef/">me</a> (<a href="mailto:panther@gate.net">panther@gate.net</a>), Josef on <a href="irc://innernet.org/#Amiga">IRC</a>.  I have also written a few other arexx scripts for Aweb, and over a hundred arexx scripts for Grapevine IRC client (mostly available on my <a href="http://www.versanet.com/~josef/">home page</a>.')
  298.     call writeln(1,'<hr><a href="http://ftp.wustl.edu/aminetbin/find?ftpmount">Latest FTPMount from Aminet</a> | <a href="http://www.versanet.com/~josef/aweb">Other Aweb Scripts</a> | <a href="http://www.versanet.com/~josef/crap/net.html">Other Net Applications</a>')
  299.     call writeln(1,'</body></html>')
  300.     call close(1)
  301.     'OPEN file://localhost/'tmpfile
  302.     exit
  303. end
  304. if server='upload' then do
  305. end
  306. do
  307.     if right(server,1)~='/' then server=server'/'
  308.     if length(file)>0 then do
  309.         filebk=file
  310.         dir=''
  311.         do until index(filebk,'/')=0
  312.             parse var filebk dirbk'/'filebk
  313.             dir=dir||dirbk'/'
  314.         end
  315.         file=filebk
  316.         url='ftp://'server||dir||file
  317.     end
  318.     else url='ftp://'server
  319.     call putawebmsg('Opening 'url' -  Please wait. <h5>(Ignore this if [Back]ing up)</h5>')
  320.     if exists(url) then do
  321.         info=statef(url)
  322.         type=word(info,1)
  323.         if type='DIR' then do
  324.             if index(file,'.')>0 then type='FILE'
  325.         end
  326.         size=word(info,2)
  327.         select
  328.             when type='DIR' then do
  329.                 if right(url,1)~='/' then url=url'/'
  330.                 call open(2,tmpfile,w)
  331.                 call writeln(2,'<html><head><title>'url'</title></head><body>')
  332.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  333.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  334.                 call writeln(2,'<input type=hidden name=function value=amiftp>')
  335. /* Changed by AmiTrix to only put AmiFTP button up if configured. */    
  336.                      if amiftpexe ~== '' then
  337.                    if(showlist(P,'AMIFTP')) then do
  338.                       call writeln(2,'<input type=submit value="Update AmiFTP!")></form>')
  339.                   end
  340.                   else do
  341.                     call writeln(2,'<input type=submit value="Load AmiFTP!")></form>')
  342.                   end
  343.                 call writeln(2,'<pre><h2>Directory of <a href="'url'">'url'</a></h2>')
  344.                 call writeln(2,'<hr>   Date          Size    Name<hr>')
  345.                 call close(2)
  346.                 address command 'list 'url' lformat "%10d %10l  <a href='url'%n>%s</a>" >>'tmpfile
  347.                 call open(2,tmpfile,a)
  348.                 call writeln(2,'</pre><hr>')
  349.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  350.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  351.                 call writeln(2,'<input type=hidden name=function value=upload>')
  352.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  353.                 call writeln(2,'<input type=submit value="Send File")></form>')
  354.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  355.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  356.                 call writeln(2,'<input type=hidden name=function value=makedir>')
  357.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  358.                 call writeln(2,'<input type=submit value="Make Dir")></form>')
  359.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  360.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  361.                 call writeln(2,'<input type=hidden name=function value=delete>')
  362.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  363.                 call writeln(2,'<input type=submit value="Delete File")></form>')
  364.                 call writeln(2,'<hr><a href="ftp://about/">AwebFTP</a> 'vers' by <a href="mailto:panther@gate.net">Josef Faulkner</a>.')
  365.                 call writeln(2,'</body></html>')
  366.                 call close(1)
  367.                 call close(2)
  368.                 'open file://localhost/'tmpfile
  369.                                 'ALLOWCMD'
  370.             end
  371.             when type='FILE' then do
  372.                 if open(11,url,r) then do
  373.                     call close(11)
  374.                     address command 'requestchoice "AWebFTP" "View or Save 'file'?" "View|Save|Cancel" pubscreen="'screen'" >t:awebftpchoice.tmp'
  375.                     call open(1,'t:awebftpchoice.tmp',r)
  376.                     text=readln(1)
  377.                     call close(1)
  378.                     select
  379.                         when text=0 then do
  380.                             call putawebmsg('Transfer aborted.')
  381.                         end
  382.                         when text=1 then do
  383.                             call putawebmsg('Downloading 'url' to view in Aweb.')
  384.                             address command copycommand' 'url' 'tmpfile' >nil:'
  385.                             'open file://localhost/'tmpfile
  386.                         end
  387.                         when text=2 then do
  388.                             address command 'requestfile drawer='savedir' file='file' pubscreen='screen' >'tmpfile
  389.                             call open(1,tmpfile,r)
  390.                             text=readln(1)
  391.                             call close(1)
  392.                             if left(text,7)~='no more' then do
  393.                                 call putawebmsg('Downloading 'file' ('size' bytes).<br> You may resume using Aweb, and a message will appear when transfer is complete.')
  394.                                 address command copycommand' 'url' 'text' >nil:'
  395.                                 call putawebmsg('Download of 'file' to 'text' complete.')
  396.                             end
  397.                             else do
  398.                                 call putawebmsg('Transfer aborted.')
  399.                             end
  400.                         end
  401.                         otherwise do
  402.                             call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #2-'text)
  403.                             exit
  404.                         end
  405.                     end
  406.                 end
  407.                 else do
  408.                     call putawebmsg('Sorry, could not open 'url' for read access.')
  409.                 end
  410.             end
  411.             otherwise do
  412.                 call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #1-'type)
  413.                 exit
  414.             end
  415.         end
  416.     end
  417.     else do
  418.         call putawebmsg('Sorry, 'url' doesn''t exist.')
  419.     end
  420. end
  421. exit
  422.  
  423. PUTAWEBMSG: procedure
  424. parse arg text
  425.     address command 'delete t:awebmsg#?.html >NIL:'
  426.     fname='t:awebmsg'time(S)'.html'
  427.     call open(4,fname,w)
  428.     call writeln(4,'<html><head><title>AwebFTP Message</title></head><body>')
  429.     call writeln(4,'<h3>'text'</h3>')
  430.     call writeln(4,'</body>')
  431.     call close(4)
  432.     'OPEN file://localhost/'fname
  433. return
  434.